package com.feifan.monthhelper.db;

import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.migration.Migration;

import com.feifan.monthhelper.bean.db.DayRecordBean;
import com.feifan.monthhelper.bean.db.LivingHabitBean;
import com.feifan.monthhelper.bean.db.LoveProtectBean;
import com.feifan.monthhelper.bean.db.MenstrualBloodBean;
import com.feifan.monthhelper.bean.db.MenstrualRecordBean;
import com.feifan.monthhelper.bean.db.PainBean;
import com.feifan.monthhelper.db.dao.DayRecordDao;
import com.feifan.monthhelper.db.dao.LivingHabitDao;
import com.feifan.monthhelper.db.dao.LoveProtectDao;
import com.feifan.monthhelper.db.dao.MenstrualBloodDao;
import com.feifan.monthhelper.db.dao.MenstrualRecordDao;
import com.feifan.monthhelper.db.dao.PainDao;

@Database(entities = {LoveProtectBean.class, LivingHabitBean.class, MenstrualBloodBean.class, MenstrualRecordBean.class, PainBean.class, DayRecordBean.class}, version = 1,exportSchema = false)
public abstract class AppDataBase extends RoomDatabase {

    public abstract LoveProtectDao getLoveProtectDao();

    public abstract LivingHabitDao getLivingHabitDao();

    public abstract PainDao getPainDao();

    public abstract MenstrualBloodDao getMenstrualBloodDao();

    public abstract MenstrualRecordDao getMenstrualRecordDao();

    public abstract DayRecordDao getDayRecordDao();

    //数据库变动添加Migration
    static final Migration MIGRATION_1_2 = new Migration(2, 3) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            database.execSQL("CREATE TABLE IF NOT EXISTS `menstrual_blood` (`date` INTEGER PRIMARY KEY NOT NULL, `level` INTEGER NOT NULL)");
            database.execSQL("CREATE TABLE IF NOT EXISTS `menstrual_record` (`start_date` INTEGER PRIMARY KEY NOT NULL, `end_date` INTEGER NOT NULL)");
            database.execSQL("CREATE TABLE IF NOT EXISTS `pain` (`date` INTEGER PRIMARY KEY NOT NULL, `level` INTEGER NOT NULL)");
        }
    };
    //数据库变动添加Migration
    static final Migration MIGRATION_2_3 = new Migration(3,4) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            database.execSQL("CREATE TABLE IF NOT EXISTS `day_record` (" +
                    "`create_date` INTEGER PRIMARY KEY NOT NULL, `blood_level` INTEGER NOT NULL DEFAULT 0, `pain_level` INTEGER NOT NULL DEFAULT 0," +
                    "`hot_water` INTEGER NOT NULL DEFAULT 0, `fruit` INTEGER NOT NULL DEFAULT 0, `sports` INTEGER NOT NULL DEFAULT 0," +
                    "`breakfast` INTEGER NOT NULL DEFAULT 0, `defecate` INTEGER NOT NULL DEFAULT 0, `protects` TEXT" +
                    ")");
        }
    };
}
